﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Student_management
{
    public partial class frmLogin : Form
    {
        Connection db = new Connection();
        public frmLogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DangNhap();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Thoat();
        }

        private void frmLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void DangNhap()
        {
            DataTable a = db.getDS("Select * from Account where Username = '" + txtUser.Text + "'" + " and Password = '" + txtPass.Text + "'");
            if (a.Rows.Count == 1)
            {
                frmMain.username = a.Rows[0]["Username"].ToString();
                frmMain.quyen = a.Rows[0]["Quyen"].ToString();
                frmMain.lop = a.Rows[0]["Malop"].ToString();
                frmMain.mon = a.Rows[0]["MaMon"].ToString();
                frmMain form = new frmMain();
                form.Show();
                Hide();
            }
            else
                MessageBox.Show("Sai Tên Đăng Nhập Hoặc Mật Khẩu!", "ĐĂNG NHẬP", MessageBoxButtons.OK);
        }
        private void Thoat()
        {
            Application.Exit();
        }
    }
}
